<#include "/admin/common/header.ftl">
<style>
    .w-e-text-container {
        height: 400px !important;
    }

    .panel-group {
        margin: 10px;
    }
</style>
<body>
<form id="infoFrom" class="form-horizontal" data-toggle="validator">
    <div class="panel-group">
        <div class="panel">
            <div class="panel-heading">基本信息</div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-md-2 control-label required">商城名称：</label>
                    <div class="col-md-2">
                        <input name="SHOP_NAME" required maxlength="8" value="${SHOP_NAME!}" placeholder="请输入商城名称，不超过8个字符" class="form-control">
                    </div>
                    <label class="col-md-2 control-label">积分换算比例：</label>
                    <div class="col-md-2">
                        <input name="POINTS_RATIO" type="number" value="${POINTS_RATIO!}" placeholder="如100积分=1元，即填写100" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">运费：</label>
                    <div class="col-md-2">
                        <div class="input-group">
                            <input name="POSTAGE" type="number" value="${POSTAGE!}" placeholder="请设置商城运费" class="form-control">
                            <span class="input-group-addon">元</span>
                        </div>
                    </div>
                    <label class="col-md-2 control-label">包邮金额：</label>
                    <div class="col-md-2">
                        <div class="input-group">
                            <input name="PACKAGE_POSTAGE" type="number" value="${PACKAGE_POSTAGE!}" placeholder="商城购物满多少包邮" class="form-control">
                            <span class="input-group-addon">元</span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">订单自动关闭：</label>
                    <div class="col-md-2">
                        <div class="input-group">
                            <input name="ORDER_AUTO_CLOSE_TIME" type="number" value="${ORDER_AUTO_CLOSE_TIME!}" placeholder="订单自动关闭时间（分钟）" class="form-control">
                            <span class="input-group-addon">分钟</span>
                        </div>
                    </div>
                    <label class="col-md-2 control-label">自动确认收货：</label>
                    <div class="col-md-2">
                        <div class="input-group">
                            <input name="ORDER_AUTO_FINISH_TIME" type="number" value="${ORDER_AUTO_FINISH_TIME!}" placeholder="发货后自动确认收货时间 (天)" class="form-control">
                            <span class="input-group-addon">天</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel">
            <div class="panel-heading">商城简介</div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-md-2 control-label">商城简介：</label>
                    <div class="col-md-6">
                        <div id="editor">${SHOP_INTRO!}</div>
                        <input type="hidden" name="SHOP_INTRO">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="footer">
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>
<#include "/admin/common/footer.ftl">
<script type="text/javascript" src="/plugins/wangEditor/wangEditor.min.js"></script>
<script type="text/javascript">
    var dlg = new $.zui.ModalTrigger({
        backdrop: 'static'
    });

    //初始化富文本编辑器
    var editor = new wangEditor('#editor');
    editor.customConfig.zIndex = 100;
    // 关闭粘贴样式的过滤
    editor.customConfig.pasteFilterStyle = false;
    editor.create();

    $("#infoFrom").validate({
        errorPlacement: function (error, element) {
            if (element.parent(".input-group").length === 0) {
                error.appendTo(element.parent());
            } else {
                error.appendTo(element.parent(".input-group").parent());
            }
        },
        submitHandler: function (form) {
            $("input[name='SHOP_INTRO']").val(editor.txt.html());
            $(form).ajaxSubmit({
                type: 'POST',
                url: '/admin/shop/saveShopConfig',
                success: function (data) {
                    successTip(data);
                }
            });
        }
    });

    $('.w-e-menu i.w-e-icon-image').parent().on('click', function () {
        dlg.show({remote: '/admin/picture/pictureSpace'});
    });

    function returnPicture(pictureData) {
        $.each(pictureData, function (index, item) {
            editor.txt.append('<img src="' + item.imgUrl + '">')
        });
        dlg.close();
    }
</script>